#include <iostream>
#include <vector>

using namespace std;

// https://leetcode.cn/problems/binary-tree-paths/description/
// 257. 二叉树的所有路径
// 给你一个二叉树的根节点 root ，按 任意顺序 ，返回所有从根节点到叶子节点的路径。
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(): val(0),left(nullptr),right(nullptr) {}
    TreeNode(int x): val(x),left(nullptr),right(nullptr) {}
};
class Solution {
public:
    vector<string> binaryTreePaths(TreeNode* root) {

        vector<string> res;
        // 递归终止条件
        if(root == nullptr)
            return res;
        // 到达叶子结点
        if(root->left == nullptr && root->right == nullptr) {
            res.push_back(to_string(root->val));
            return res;
        }

        vector<string> leftS = binaryTreePaths(root->left);
        for(int i = 0; i < leftS.size(); i++)
            res.push_back(to_string(root->val) + "->" + leftS[i]);

        vector<string> rightS = binaryTreePaths(root->right);
        for(int i = 0; i < rightS.size(); i++)
            res.push_back(to_string(root->val) + "->" + rightS[i]);

        return res;
    }
};

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
